import html2canvas from 'html2canvas';


/*
*  数组去重
*  https://mp.weixin.qq.com/s/jJDdFMGSKlqaK_nXAjWULA
* */
export const arrayDeDuplication = (arr) => [...new Set(arr)];

/*
* 点击截图
* */
export function toScreenShotAndDownload(htmlNode) {
  const timestamp = new Date().getTime();
  return html2canvas(htmlNode).then(canvas => {
    const link = document.createElement('a'); // 创建一个超链接对象实例
    const event = new MouseEvent('click'); // 创建一个鼠标事件的实例
    // link.download = `近聘截图_${timestamp}.png`; // 设置要下载的图片的名称
    var mA = document.createElement("img");
    mA.src = canvas.toDataURL()
    mA.setAttribute('download', `近聘截图_${timestamp}.png`);
    mA.setAttribute('id', 'downloadImg');
    mA.setAttribute('width', '100%');
    mA.setAttribute('style', 'display:block');
    document.getElementById('saveToPhone').appendChild(mA)
    mA.click();
    // link.href = canvas.toDataURL(); // 将图片的URL设置到超链接的href中
    // link.dispatchEvent(event); // 触发超链接的点击事件
  });
};





// 唤醒地图app导航
// URL Schemes方案  http://uusama.com/493.html






/*
*
* 正则提取：省、市、县的正则
*
* */


export const provinceAndCityReg = /.+?(省|市|自治区|自治州|县|区)/g;

// 工作状态说明
export const workStatusDesc = {
  Leave: '自离',
  Resign: '辞职',
  OnJob: '在职'
};

export const workStatusDescColor = {
  Leave: 'warning',
  Resign: 'danger',
  OnJob: 'success',
};

// 辞职的批准状态：
export const workQuitStatusObj = {
  'Approval':'辞职批准',
  'NonApproval': '辞职不批准',
  'Applying': '辞职申请中',
};

export const workQuitAuditStatusColor = (auditStatus) => {
  let colorBbj = {
    'Approval':'#07C160',
    'NonApproval': '#EE0A24',
    'Applying': '#1989FA',
  };

  return colorBbj[auditStatus]
};


// 将高德（谷歌、腾讯）坐标转换为百度坐标
export function gd_convent_bd(gd_lng, gd_lat) {
  var pi = 3.14159265358979324 * 3000.0 / 180.0;
  var x = gd_lng;
  var y = gd_lat;
  var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * pi);
  var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * pi);
  var bd_lng = z * Math.cos(theta) + 0.0065;
  var bd_lat = z * Math.sin(theta) + 0.006;
  var data = {
    x: bd_lng.toFixed(10),
    y: bd_lat.toFixed(10),
  }
  return data;
};



// 将百度坐标转换为高德坐标
export function bd_convent_gd(points) {
  var arr = points.split(" ");
  var bd_lng = arr[0];
  var bd_lat = arr[1];
  var pi = 3.14159265358979324 * 3000.0 / 180.0;
  var x = bd_lng - 0.0065;
  var y = bd_lat - 0.006;
  var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * pi);
  var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * pi);
  var gd_lng = z * Math.cos(theta);
  var gd_lat = z * Math.sin(theta);
  var data = gd_lng + " " + gd_lat;
  return data;
}










